package ll1;

import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;

import scanner.MiniReScan;


public class LL1Tester {
	public static void main(String[] args){
		String filename = "OutTest.dfa";
		FileWriter writer;
		JFileChooser opt = new JFileChooser();
		opt.showDialog(null, "Open Target File To Run On");				// Sample Input in the same folder as src, you can move it to My Documents folder or change the directory in the code.
		MiniReScan s;
		try {
			s = new MiniReScan(opt.getSelectedFile().getAbsolutePath());
		} catch (IOException e) {
			s = null;
			e.printStackTrace();
		}

		LL1Gen generator = new LL1Gen(s.getTokenList(), s.getRules(),s.getStartToken());
		//System.out.println(s.getStartToken());
		System.out.println("TOKENS: \n" + s.getTokenList() + "\n");
		System.out.println("GRAMMAR: \n" + generator.toString() + "\n");
		System.out.println("NONTERMIALS: \n" + generator.theNonTerminals() + "\n");
		System.out.println("FIRST SET: \n" + generator.theFirstSets() + "\n");
		System.out.println("FOLLOW SET: \n" + generator.theFollowSets() + "\n");
		System.out.println("LL(1) PARSE TABLE: \n" + generator.printParseTable() + "\n");
		
		LL1Driver driver = new LL1Driver(generator.getTable(), s.getStartToken());
		System.out.println("LL1 Parser StackTrace:");
		System.out.println(driver.parseInput("begin combos = ( find \'[a-z]*combo\' in \"sample1.txt\" ) ; num_combos = # combos ; print ( num_combos ) ; replace \'[a-z]*combo\' with \"kill\" in \"sample1.txt\" >! \"WhatHappensInLeagueOfLegends.txt\" ; ko = ( find \'[a-z]+\' in \"WhatHappensInLeagueOfLegends.txt\" ) ; print ( ko ) ; replace \'killa[a-z]*\' with \"wombo\" in \"sample1.txt\" >! \"WhatHappensInSuperSmash.txt\" ; smash = ( find \'[a-z]+\' in \"WhatHappensInSuperSmash.txt\" ) ;"));
		System.out.println(driver.parseInput("print ( smash ) ; end"));
		//System.out.println(driver.parseInput("begin print ( num_combos ) ; end"));
	}
}
